package com.example.haojiutao.service.impl;

import com.example.haojiutao.mapper.HistoryMapper;
import com.example.haojiutao.model.domain.History;
import com.example.haojiutao.common.Result;


import com.example.haojiutao.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Description: 浏览记录
 * @Author: ma_jun
 * @CreateTime: 2023/12/13 9:57
 */
@Service
public class HistoryServiceImpl implements HistoryService {
    @Autowired
    private HistoryMapper historyMapper;

    @Override
    public Result insertHistory(History history) {
        history.setCreateTime(new Date());
        int row=historyMapper.insertHistory(history);
        if(row==1){
            return Result.success("插入成功");
        }
        return Result.faile("插入失败");
    }

    @Override
    public List<History> selectAll(Integer userId) {
        List<History> histories = historyMapper.selectAll(userId);
        return histories;
    }

    @Override
    public Result deleteById(Integer goodsId) {
        History history = new History();
        history.setDelFlag(1);
        int rows = historyMapper.updateDeleteById(goodsId);
        if (rows == 1) {
            return Result.success("删除成功");
        }
        return Result.faile("删除失败");
    }
}
